home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / wgdb-42.lha / wgdb-4.2 / gdb / target.h < prev    next >
C/C++ Source or Header  |  1992-09-11  |  16KB  |  429 lines

  1. /* Interface between GDB and target environments, including files and processes
  2.    Copyright 1990, 1991 Free Software Foundation, Inc.
  3.    Contributed by Cygnus Support.  Written by John Gilmore.
  4.  
  5. This file is part of GDB.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* This include file defines the interface between the main part
  22.    of the debugger, and the part which is target-specific, or
  23.    specific to the communications interface between us and the
  24.    target.
  25.  
  26.    A TARGET is an interface between the debugger and a particular 
  27.    kind of file or process.  Targets can be STACKED in STRATA, 
  28.    so that more than one target can potentially respond to a request.
  29.    In particular, memory accesses will walk down the stack of targets
  30.    until they find a target that is interested in handling that particular
  31.    address.  STRATA are artificial boundaries on the stack, within
  32.    which particular kinds of targets live.  Strata exist so that
  33.    people don't get confused by pushing e.g. a process target and then
  34.    a file target, and wondering why they can't see the current values
  35.    of variables any more (the file target is handling them and they
  36.    never get to the process target).  So when you push a file target,
  37.    it goes into the file stratum, which is always below the process
  38.    stratum.  */
  39.  
  40. #include "bfd.h"
  41.  
  42. enum strata {
  43.     dummy_stratum,        /* The lowest of the low */
  44.     file_stratum,        /* Executable files, etc */
  45.     core_stratum,        /* Core dump files */
  46.     process_stratum,    /* Executing processes */
  47. };
  48.  
  49. struct target_ops {
  50.     char  *to_shortname;        /* Name this target type */
  51.     char  *to_longname;        /* Name for printing */
  52.     /* Documentation.  Does not include trailing newline, and
  53.        starts with a one-line description (probably similar to
  54.        to_longname).  */
  55.     char  *to_doc;
  56. #ifdef __STDC__
  57.     void (*to_open) (char *name, int from_tty);
  58.     void (*to_close) (int quitting);
  59.     void (*to_attach) (char *name, int from_tty);
  60.     void (*to_detach) (char *args, int from_tty);
  61.     void (*to_resume) (int step, int siggnal);
  62.     int  (*to_wait)   (int *status);
  63.     void (*to_fetch_registers) (int regno);
  64.     int  (*to_store_registers) (int regno);
  65.     void (*to_prepare_to_store) ();
  66.     void (*to_convert_to_virtual) (int regnum, char *from, char *to);
  67.     void (*to_convert_from_virtual) (int regnum, char *from, char *to);
  68.     int  (*to_xfer_memory) (CORE_ADDR memaddr, char *myaddr, int len, int w,
  69.                 struct target_ops *);
  70.     void (*to_files_info) (struct target_ops *);
  71.     int  (*to_insert_breakpoint) (CORE_ADDR addr, char *save);
  72.     int  (*to_remove_breakpoint) (CORE_ADDR addr, char *save);
  73.     void  (*to_terminal_init) ();
  74.     void  (*to_terminal_inferior) ();
  75.     void  (*to_terminal_ours_for_output) ();
  76.     void  (*to_terminal_ours) ();
  77.     void  (*to_terminal_info) (char *arg, int from_tty);
  78.     void  (*to_kill) (char *arg, int from_tty);
  79.     void  (*to_load) (char *arg, int from_tty);
  80. struct value *(*to_call_function) (struct value *function,
  81.                    int nargs, struct value **args);
  82.     int   (*to_lookup_symbol) (char *name, CORE_ADDR *addrp);
  83.     void  (*to_create_inferior) (char *exec, char *args, char **env);
  84.     void  (*to_mourn_inferior) ();
  85.     enum strata to_stratum;
  86. struct target_ops *to_next;
  87.     int    to_has_all_memory;
  88.     int    to_has_memory;
  89.     int    to_has_stack;
  90.     int    to_has_registers;
  91.     int    to_has_execution;
  92. struct section_table *sections;
  93. struct section_table *sections_end;
  94.     int     to_magic;
  95. /* Need sub-structure for target machine related rather than comm related? */
  96. #else  /* STDC */
  97.     void (*to_open) ();
  98.     void (*to_close) ();
  99.     void (*to_attach) ();
  100.     void (*to_detach) ();
  101.     void (*to_resume) ();
  102.     int  (*to_wait)   ();
  103.     void (*to_fetch_registers) ();
  104.     int  (*to_store_registers) ();
  105.     void (*to_prepare_to_store) ();
  106.     void (*to_convert_to_virtual) ();
  107.     void (*to_convert_from_virtual) ();
  108.     int  (*to_xfer_memory) ();
  109.     void (*to_files_info) ();
  110.     int  (*to_insert_breakpoint) ();
  111.     int  (*to_remove_breakpoint) ();
  112.     void  (*to_terminal_init) ();
  113.     void  (*to_terminal_inferior) ();
  114.     void  (*to_terminal_ours_for_output) ();
  115.     void  (*to_terminal_ours) ();
  116.     void  (*to_terminal_info) ();
  117.     void  (*to_kill) ();
  118.     void  (*to_load) ();
  119. struct value *(*to_call_function) ();
  120.     int   (*to_lookup_symbol) ();
  121.     void  (*to_create_inferior) ();
  122.     void  (*to_mourn_inferior) ();
  123.     enum strata to_stratum;
  124. struct target_ops *to_next;
  125.     int    to_has_all_memory;
  126.     int    to_has_memory;
  127.     int    to_has_stack;
  128.     int    to_has_registers;
  129.     int    to_has_execution;
  130. struct section_table *sections;
  131. struct section_table *sections_end;
  132.     int     to_magic;
  133. /* Need sub-structure for target machine related rather than comm related? */
  134. #endif
  135. };
  136.  
  137. /* Magic number for checking ops size.  If a struct doesn't end with this
  138.    number, somebody changed the declaration but didn't change all the
  139.    places that initialize one.  */
  140.  
  141. #define    OPS_MAGIC    3840
  142.  
  143. /* The ops structure for our "current" target process.  */
  144.  
  145. extern struct target_ops    *current_target;
  146.  
  147. /* Define easy words for doing these operations on our current target.  */
  148.  
  149. #define    target_shortname    (current_target->to_shortname)
  150. #define    target_longname        (current_target->to_longname)
  151.  
  152. /* The open routine takes the rest of the parameters from the command,
  153.    and (if successful) pushes a new target onto the stack.
  154.    Targets should supply this routine, if only to provide an error message.  */
  155. #define    target_open(name, from_tty)    \
  156.     (*current_target->to_open) (name, from_tty)
  157.  
  158. /* Does whatever cleanup is required for a target that we are no longer
  159.    going to be calling.  Argument says whether we are quitting gdb and
  160.    should not get hung in case of errors, or whether we want a clean
  161.    termination even if it takes a while.  This routine is automatically
  162.    always called just before a routine is popped off the target stack.
  163.    Closing file descriptors and freeing memory are typical things it should
  164.    do.  */
  165.  
  166. #define    target_close(quitting)    \
  167.     (*current_target->to_close) (quitting)
  168.  
  169. /* Attaches to a process on the target side.  */
  170.  
  171. #define    target_attach(args, from_tty)    \
  172.     (*current_target->to_attach) (args, from_tty)
  173.  
  174. /* Takes a program previously attached to and detaches it.
  175.    The program may resume execution (some targets do, some don't) and will
  176.    no longer stop on signals, etc.  We better not have left any breakpoints
  177.    in the program or it'll die when it hits one.  ARGS is arguments
  178.    typed by the user (e.g. a signal to send the process).  FROM_TTY
  179.    says whether to be verbose or not.  */
  180.  
  181. #define    target_detach(args, from_tty)        \
  182.     (*current_target->to_detach) (args, from_tty)
  183.  
  184. /* Resume execution of the target process.  STEP says whether to single-step
  185.    or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
  186.    to the target, or zero for no signal.  */
  187.  
  188. #define    target_resume(step, siggnal)    \
  189.     (*current_target->to_resume) (step, siggnal)
  190.  
  191. /* Wait for inferior process to do something.  Return pid of child,
  192.    or -1 in case of error; store status through argument pointer STATUS.  */
  193.  
  194. #define    target_wait(status)        \
  195.     (*current_target->to_wait) (status)
  196.  
  197. /* Fetch register REGNO, or all regs if regno == -1.  No result.  */
  198.  
  199. #define    target_fetch_registers(regno)    \
  200.     (*current_target->to_fetch_registers) (regno)
  201.  
  202. /* Store at least register REGNO, or all regs if REGNO == -1.
  203.    It can store as many registers as it wants to, so the entire registers
  204.    array must be valid.  Result is 0 for success, -1 for problems.  */
  205.  
  206. #define    target_store_registers(regs)    \
  207.     (*current_target->to_store_registers) (regs)
  208.  
  209. /* Get ready to modify the registers array.  On machines which store
  210.    individual registers, this doesn't need to do anything.  On machines
  211.    which store all the registers in one fell swoop, this makes sure
  212.    that REGISTERS contains all the registers from the program being
  213.    debugged.  */
  214.  
  215. #define    target_prepare_to_store()    \
  216.     (*current_target->to_prepare_to_store) ()
  217.  
  218. /* Convert data from raw format for register REGNUM
  219.    to virtual format for register REGNUM.  */
  220.  
  221. #define    target_convert_to_virtual(regnum, from, to)    \
  222.     (*current_target->to_convert_to_virtual) (regnum, from, to)
  223.     
  224. /* Convert data from virtual format for register REGNUM
  225.    to raw format for register REGNUM.  */
  226.  
  227. #define    target_convert_from_virtual(regnum, from, to)    \
  228.     (*current_target->to_convert_from_virtual) (regnum, from, to)
  229.  
  230. /* Reading and writing memory actually happens through a glue
  231.    function which iterates across the various targets.  Result is
  232.    0 for success, or an errno value.  */
  233.  
  234. #ifdef __STDC__
  235. /* Needs defs.h for CORE_ADDR */
  236. extern int target_read_memory(CORE_ADDR memaddr, char *myaddr, int len);
  237. extern int target_write_memory(CORE_ADDR memaddr, char *myaddr, int len);
  238. extern int target_xfer_memory(CORE_ADDR memaddr, char *myaddr, int len,
  239.                   int write);
  240. #else
  241. extern int target_read_memory();
  242. extern int target_write_memory();
  243. extern int target_xfer_memory();
  244. #endif
  245.  
  246. /* Print a line about the current target.  */
  247.  
  248. #define    target_files_info()    \
  249.     (*current_target->to_files_info) (current_target)
  250.  
  251. /* Insert a breakpoint at address ADDR in the target machine.
  252.    SAVE is a pointer to memory allocated for saving the
  253.    target contents.  It is guaranteed by the caller to be long enough
  254.    to save "sizeof BREAKPOINT" bytes.  Result is 0 for success, or
  255.    an errno value.  */
  256.  
  257. #define    target_insert_breakpoint(addr, save)    \
  258.     (*current_target->to_insert_breakpoint) (addr, save)
  259.  
  260. /* Remove a breakpoint at address ADDR in the target machine.
  261.    SAVE is a pointer to the same save area 
  262.    that was previously passed to target_insert_breakpoint.  
  263.    Result is 0 for success, or an errno value.  */
  264.  
  265. #define    target_remove_breakpoint(addr, save)    \
  266.     (*current_target->to_remove_breakpoint) (addr, save)
  267.  
  268. /* Initialize the terminal settings we record for the inferior,
  269.    before we actually run the inferior.  */
  270.  
  271. #define target_terminal_init() \
  272.     (*current_target->to_terminal_init) ()
  273.     
  274. /* Put the inferior's terminal settings into effect.
  275.    This is preparation for starting or resuming the inferior.  */
  276.  
  277. #define target_terminal_inferior() \
  278.     (*current_target->to_terminal_inferior) ()
  279.  
  280. /* Put some of our terminal settings into effect,
  281.    enough to get proper results from our output,
  282.    but do not change into or out of RAW mode
  283.    so that no input is discarded.
  284.  
  285.    After doing this, either terminal_ours or terminal_inferior
  286.    should be called to get back to a normal state of affairs.  */
  287.  
  288. #define target_terminal_ours_for_output() \
  289.     (*current_target->to_terminal_ours_for_output) ()
  290.  
  291. /* Put our terminal settings into effect.
  292.    First record the inferior's terminal settings
  293.    so they can be restored properly later.  */
  294.  
  295. #define target_terminal_ours() \
  296.     (*current_target->to_terminal_ours) ()
  297.  
  298. /* Print useful information about our terminal status, if such a thing
  299.    exists.  */
  300.  
  301. #define target_terminal_info(arg, from_tty) \
  302.     (*current_target->to_terminal_info) (arg, from_tty)
  303.  
  304. /* Kill the inferior process.   Make it go away.  */
  305.  
  306. #define target_kill(arg, from_tty) \
  307.     (*current_target->to_kill) (arg, from_tty)
  308.  
  309. /* Load an executable file into the target process.  This is expected to
  310.    not only bring new code into the target process, but also to update
  311.    GDB's symbol tables to match.  */
  312.  
  313. #define target_load(arg, from_tty) \
  314.     (*current_target->to_load) (arg, from_tty)
  315.  
  316. /* Perform a function call in the inferior.
  317.    ARGS is a vector of values of arguments (NARGS of them).
  318.    FUNCTION is a value, the function to be called.
  319.    Returns a value representing what the function returned.
  320.    May fail to return, if a breakpoint or signal is hit
  321.    during the execution of the function.  */
  322.  
  323. #define target_call_function(function, nargs, args)     \
  324.   (*current_target->to_call_function) (function, nargs, args)
  325.  
  326. /* Look up a symbol in the target's symbol table.  NAME is the symbol
  327.    name.  ADDRP is a CORE_ADDR * pointing to where the value of the symbol
  328.    should be returned.  The result is 0 if successful, nonzero if the
  329.    symbol does not exist in the target environment.  This function should
  330.    not call error() if communication with the target is interrupted, since
  331.    it is called from symbol reading, but should return nonzero, possibly
  332.    doing a complain().  */
  333.  
  334. #define target_lookup_symbol(name, addrp)     \
  335.   (*current_target->to_lookup_symbol) (name, addrp)
  336.  
  337. /* Start an inferior process and set inferior_pid to its pid.
  338.    EXEC_FILE is the file to run.
  339.    ALLARGS is a string containing the arguments to the program.
  340.    ENV is the environment vector to pass.  Errors reported with error().
  341.    On VxWorks and various standalone systems, we ignore exec_file.  */
  342.  
  343. #define    target_create_inferior(exec_file, args, env)    \
  344.     (*current_target->to_create_inferior) (exec_file, args, env)
  345.  
  346. /* The inferior process has died.  Do what is right.  */
  347.  
  348. #define    target_mourn_inferior()    \
  349.     (*current_target->to_mourn_inferior) ()
  350.  
  351. /* Pointer to next target in the chain, e.g. a core file and an exec file.  */
  352.  
  353. #define    target_next \
  354.     (current_target->to_next)
  355.  
  356. /* Does the target include all of memory, or only part of it?  This
  357.    determines whether we look up the target chain for other parts of
  358.    memory if this target can't satisfy a request.  */
  359.  
  360. #define    target_has_all_memory    \
  361.     (current_target->to_has_all_memory)
  362.  
  363. /* Does the target include memory?  (Dummy targets don't.)  */
  364.  
  365. #define    target_has_memory    \
  366.     (current_target->to_has_memory)
  367.  
  368. /* Does the target have a stack?  (Exec files don't, VxWorks doesn't, until
  369.    we start a process.)  */
  370.    
  371. #define    target_has_stack    \
  372.     (current_target->to_has_stack)
  373.  
  374. /* Does the target have registers?  (Exec files don't.)  */
  375.  
  376. #define    target_has_registers    \
  377.     (current_target->to_has_registers)
  378.  
  379. /* Does the target have execution?  Can we make it jump (through hoops),
  380.    or pop its stack a few times, or set breakpoints?  */
  381.  
  382. #define    target_has_execution    \
  383.     (current_target->to_has_execution)
  384.  
  385. /* Routines for maintenance of the target structures...
  386.  
  387.    add_target:   Add a target to the list of all possible targets.
  388.  
  389.    push_target:  Make this target the top of the stack of currently used
  390.          targets, within its particular stratum of the stack.  Result
  391.          is 0 if now atop the stack, nonzero if not on top (maybe
  392.          should warn user).
  393.  
  394.    unpush_target: Remove this from the stack of currently used targets,
  395.          no matter where it is on the list.  Returns 0 if no
  396.          change, 1 if removed from stack.
  397.  
  398.    pop_target:     Remove the top thing on the stack of current targets.  */
  399.  
  400. #ifdef __STDC__
  401. void add_target (struct target_ops *);
  402. int push_target (struct target_ops *);
  403. int unpush_target (struct target_ops *);
  404. void target_preopen (int);
  405. void pop_target (void);
  406. #else
  407. void add_target ();
  408. int push_target ();
  409. int unpush_target ();
  410. void target_preopen ();
  411. void pop_target ();
  412. #endif
  413.  
  414. /* Struct section_table maps address ranges to file sections.  It is
  415.    mostly used with BFD files, but can be used without (e.g. for handling
  416.    raw disks, or files not in formats handled by BFD).  */
  417.  
  418. struct section_table {
  419.   CORE_ADDR addr;        /* Lowest address in section */
  420.   CORE_ADDR endaddr;        /* 1+highest address in section */
  421.   sec_ptr   sec_ptr;        /* BFD section pointer */
  422.   bfd       *bfd;        /* BFD file pointer */
  423. };
  424.  
  425. /* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
  426.    Returns 0 if OK, 1 on error.  */
  427.  
  428. int build_section_table ();    
  429.